package cn.amebius.simpledocker.entity.model;

import cn.amebius.simpledocker.entity.po.DockerPo;
import cn.hutool.core.date.DateUtil;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.Info;
import com.github.dockerjava.api.model.Version;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Date;

/**
 * docker主机的model类
 * @author 阿伟
 * @date 2023/7/31 15:15
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class DockerClientModel {



    private Boolean alive;
    private DockerClient dockerClient;
    private DockerPo docker;

    private Integer containers;
    private Integer containersRunning;
    private Integer containersStopped;
    private Integer containersPaused;
    private Integer images;

    private String architecture;
    private String kernelVersion;
    private String osType;
    private String operatingSystem;
    private String apiVersion;
    private String goVersion;
    private Date buildTime;

    private String id;
    private String dockerRootDir;
    private Long memTotal;
    private Integer cpu;

    public void setBaseInfo(Integer containers,Integer containersRunning,Integer containersStopped, Integer containersPaused,Integer images) {
        this.containers = containers;
        this.containersRunning = containersRunning;
        this.containersPaused = containersPaused;
        this.containersStopped = containersStopped;
        this.images = images;
    }

    public void setSystemInfo(String architecture,String kernelVersion,String osType, String operatingSystem,String apiVersion,String goVersion, Date buildTime) {
        this.architecture = architecture;
        this.kernelVersion = kernelVersion;
        this.osType = osType;
        this.operatingSystem = operatingSystem;
        this.apiVersion = apiVersion;
        this.goVersion = goVersion;
        this.buildTime = buildTime;
    }

    public void setDataInfo(String id,String dockerRootDir,Long memTotal,Integer cpu) {
        this.id = id;
        this.dockerRootDir = dockerRootDir;
        this.memTotal = memTotal;
        this.cpu = cpu;
    }

    public void setInfoAndVersion(Info info, Version version) {
        this.setSystemInfo(info.getArchitecture(),info.getKernelVersion(),info.getOsType(),info.getOperatingSystem()
                , version.getApiVersion(),version.getGoVersion(),DateUtil.parse(version.getBuildTime()));
        this.setDataInfo(info.getId(),info.getDockerRootDir(),info.getMemTotal(),info.getNCPU());
        this.setBaseInfo(info.getContainers(),info.getContainersRunning(),info.getContainersStopped(),info.getContainersPaused(),info.getImages());
    }

    public boolean isAlive() {
        return this.alive;
    }


}
